package com.fooddelivery.service;

import com.fooddelivery.dao.OrderDAO;
import com.fooddelivery.dao.OrderItemDAO;
import com.fooddelivery.model.Order;
import com.fooddelivery.model.OrderItem;

import java.util.List;

public class OrderService {
    private OrderDAO orderDAO = new OrderDAO();
    private OrderItemDAO orderItemDAO = new OrderItemDAO();

    public void placeOrder(Order order, List<OrderItem> orderItems) {
        orderDAO.addOrder(order);
        for (OrderItem orderItem : orderItems) {
            orderItem.setOrderId(order.getId());
            orderItemDAO.addOrderItem(orderItem);
        }
    }

    public List<Order> getOrdersByUserId(int userId) {
        return orderDAO.getOrdersByUserId(userId);
    }
}
